/*
package com.temi.iot.jwt;

import com.temi.iot.exception.BizExceptionEnum;
import com.temi.iot.exception.ThrowsKit;
import com.temi.iot.jwt.annotion.Permission;
import com.temi.iot.jwt.enums.PermissionEnums;
import com.temi.iot.jwt.model.TokenValue;
import com.temi.iot.kit.StrKit;
import com.temi.iot.util.IPUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

*/
/**
 * Created by
 *
 * @author sheng
 * @date 18/3/19.
 *//*


//@Component
public class LoginFilter implements HandlerInterceptor {

    @Autowired
    private TokenInterface tokenInterface;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (!(handler instanceof HandlerMethod)) {
            return true;
        }
        //获取请求的方法
        HandlerMethod handlerMethod = (HandlerMethod) handler;
        //获取permission注解
        Permission permission = handlerMethod.getMethodAnnotation(Permission.class);
        //用户请求的原始ip
        String ip = IPUtils.getClientAddress(request).split(",")[0];
        request.setAttribute("ip", ip);
        if (permission != null) {
            //获取token
            String token = request.getHeader("Authorization");
            if (StrKit.isEmpty(token)) {
                token = request.getParameter("Authorization");
            }
            TokenValue tokenValue = tokenInterface.verifyToken(token);
            int permissionValue = 0;
            for (PermissionEnums permissionEnums : permission.value()) {
                permissionValue += permissionEnums.per;
            }
            long per = tokenValue.getPer();
            long l = per & permissionValue;
            if ((tokenValue.getPer() & permissionValue) == 0) {
                ThrowsKit.error(BizExceptionEnum.NO_PERMITION);
            }

            request.setAttribute("userId", tokenValue.getRid());
            request.setAttribute("project", tokenValue.getPro());
            request.setAttribute("per", tokenValue.getPer());
            request.setAttribute("openId", tokenValue.getOid());
            request.setAttribute("phone",tokenValue.getPhoneNum());



        } else{
            String token = request.getHeader("Authorization");
            if (StrKit.isEmpty(token)) {
                token = request.getParameter("Authorization");
            }
            if (token!=null &&token.length()>0){
                TokenValue tokenValue = tokenInterface.verifyToken(token);
                request.setAttribute("userId", tokenValue.getRid());
                request.setAttribute("project", tokenValue.getPro());
                request.setAttribute("per", tokenValue.getPer());
                request.setAttribute("openId", tokenValue.getOid());
                request.setAttribute("phone",tokenValue.getPhoneNum());
            }
        }
        return true;
    }
}
*/
